package com.ggs.starbug.controller;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.ggs.starbug.entity.R;
import com.ggs.starbug.entity.TimerTask;
import com.ggs.starbug.service.ITimerTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Starbug
 * @since 2021-12-27
 */
@RestController
@RequestMapping("/timer-task")
public class TimerTaskController {

    @Autowired
    private ITimerTaskService timerService;

    //添加定时任务
    @PostMapping("add")
    public R addTimerTask(@RequestBody TimerTask timerTask) {
        TimerTask result = timerService.addTimerTask(timerTask);
        return R.ok().data(result);
    }

    @DeleteMapping("/delete/{id}")
    public R deleteTimerTask(@PathVariable Long id) {
        boolean result = timerService.deleteTimerTask(id);
        return R.ok().data(result);
    }


    @PutMapping("/update")
    public R updateTimerTask(@RequestBody TimerTask timerTask) {
        boolean result = timerService.updateTimerTask(timerTask);
        return R.ok().data(result);
    }

    @PutMapping("/add/{ttlTime}")
    public R addAndTTLTimeQueue(@RequestBody TimerTask timerTask, @PathVariable("ttlTime") String ttlTime) {
        boolean result = timerService.addAndTTLTimeQueue(timerTask, ttlTime);
        return R.ok().data(result);
    }


}
